{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ckpt size before: 51211.11 MB\n",
      "ckpt size after: 17070.40 MB\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "from pathlib import Path\n",
    "\n",
    "ckpt_path = \"/hpc2hdd/home/xzou428/Yuhao/HiGPT-tune-lightning/checkpoints/higpt-stage2-llama3-pr-epoch30-8192-full_finetune/lightning_logs/version_1/model_epoch=17-step=900.ckpt\"\n",
    "\n",
    "print(f\"ckpt size before: {Path(ckpt_path).stat().st_size / 1024 ** 2:.2f} MB\")\n",
    "\n",
    "ckpt = torch.load(ckpt_path)\n",
    "\n",
    "torch.save({\"state_dict\": ckpt[\"state_dict\"]}, ckpt_path)\n",
    "\n",
    "print(f\"ckpt size after: {Path(ckpt_path).stat().st_size / 1024 ** 2:.2f} MB\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.14 ('yuh')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "92619f85c62eb73280c07ca2268c8e47b90999a589aa097a1a08a504bd2fb2c6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
